# -*- conding:UTF-8 -*-

'''
@ Project: funny
@ File: main.py
@ Author: 韩成瑾
@ Date：2022/10/13 20:42

'''

import datetime

from download import download as dl
import os
from pinjieMP3 import pinjie
from random import shuffle

f = open('C:/mine/my_word_list.txt')  # 此处是单词列表，使用换行作为单词与单词之间的间隔
word_list = f.readlines()
word_list = [word.replace("\n", "") for word in word_list]

f.close()

dl("英音", word_list)  # 在此处修改英音还是美音
type = 1  # 0为美音，1为英音  # 在此处也要修改英音还是美音

d_word_list = []

# 将单词列表随机打乱，注释掉这一行就是按照输入顺序进行生成的
shuffle(word_list)

d_word_list.append("_2")
d_word_list.append("_2")

for word in word_list:
    d_word_list.append(word)
    d_word_list.append("_2")
    d_word_list.append(word)
    d_word_list.append("_2")
    d_word_list.append("_2")

mp3_file_path_list = []
dirRoot = os.path.dirname(os.path.abspath(__file__))

out_put_div = os.path.join(dirRoot, "output")

# 输出打乱后的列表
out_name = datetime.datetime.now().strftime('[%Y-%m-%d]%H-%M-%S.txt')
f = open(out_put_div + '\\' + out_name, "w")
f.writelines([word + "\n" for word in word_list])
f.close()

for word in d_word_list:
    word = word.lower()  # 小写
    fileName = word + '.mp3'

    if 0 == type:
        dirSpeech = os.path.join(dirRoot, 'Speech_US')  # 美音库
    else:
        dirSpeech = os.path.join(dirRoot, 'Speech_EN')  # 英音库

    filePath = os.path.join(dirSpeech, fileName)

    # 判断是否存在这个MP3文件
    if os.path.exists(filePath):
        mp3_file_path_list.append(filePath)
    else:
        print("【ERROR】音频文件不存在造成错误: ", filePath)

pinjie(mp3_file_path_list, out_put_div)

print("----程序结束----")

